//新增
function addReportInfo() {
    var data = {stat: 1};
    if (data) {
        showReportInfoWindow(data);
    }
}

//编辑
function editReportInfo() {
    var row = grid.getSelected();
    if (row) {
        showReportInfoWindow(row);
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//回复
function replyInfo() {
    var row = grid.getSelected();
    if (row) {
        showReplyWindow(row);
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//查看回复
function look() {
    var row = grid.getSelected();
    if (row) {
        changeState(row);
        showReplyInfoWindow(row);
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//上报
function report() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: encodeURI("/azbj/sbxtgl/reportInfoManage/report/" + row.id),
            cache: false,
            success: function (result) {
                if (result.code == 1) {
                    mini.alert("上报成功");
                    grid.reload();
                } else {
                    mini.alert("上报失败");
                }
                grid.reload();
            }

        });
    } else {
        mini.alert("请至少选中一条记录");
    }
}

//撤回
function withdraw() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: encodeURI("/azbj/sbxtgl/reportInfoManage/withdraw/" + row.id),
            cache: false,
            success: function (result) {
                if (result.code == 1) {
                    mini.alert("撤回成功");
                    grid.reload();
                } else {
                    mini.alert("撤回失败");
                }
                grid.reload();
            }
        });
    } else {
        mini.alert("请至少选中一条记录");
    }
}

//新增跳转页面
function showReportInfoWindow(row) {
    commonEdit("/azbj/sbxtgl/reportInfoManage/edit", "上报协调管理", row, "55%", "55%", true, false, true, callback);

    function callback() {
        grid.reload();
    }
}

//回复跳转页面
function showReplyWindow(row) {
    commonEdit("/azbj/sbxtgl/replyInfo/edit", "上报协调回复", row, "55%", "80%", true, false, true, callback);

    function callback() {
        grid.reload();
    }
}

//查看跳转页面
function showReplyInfoWindow(row) {
    commonEdit("/azbj/sbxtgl/reportInfoManage/lookUp", "上报协调管理", row, "60%", "55%", true, false, true, callback);

    function callback() {
        grid.reload();
    }
}

//修改查看状态
function changeState(row) {
    if (row) {
        $.ajax({
            url: encodeURI("/azbj/sbxtgl/reportInfoManage/changeState/" + row.id),
            cache: false,
            success: function (result) {
                grid.reload();
            }
        });
    } else {
        mini.alert("请至少选中一条记录");
    }
}

//格式化日期函数
function onDateRenderer(e) {
    var date = new Date(e.value);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    var formatTime = Y + M + D + h + m + s;
    return formatTime;
}

//上报类型code转换
function onGetSbTypeName(e) {
    var sbtype = e.value;
    if (sbtype == 1) {
        return "重大案件";
    } else if (sbtype == 2) {
        return "重大事件";
    } else if (sbtype == 3) {
        return "业务协调请示";
    } else {
        return "其他";
    }
}